System and method for determining an index of an object in a sequence of objects

ABSTRACT

A method for determining an index of an object in a sequence of objects, the method comprising the steps of: obtaining a unique identifier value of a given object O; obtaining a query definition Q of a sequence, the Q query including an order definition according to a parameter of the O object; constructing a Q′ query based on the Q query, the Q′ query being different from the Q query by having a reversed ordering of results, with respect to the Q query, and providing results having said parameter value of objects preceding or matching the parameter value of the object O in the sequence of objects in the Q query result set; executing the Q′ query by a query execution engine; checking whether the object O is present as the first item in Q′ result set and in case it is, obtaining the index of the O object in Q sequence by retrieving objects count of the Q′ result set.

The present invention relates to a system and method for determining anindex of an object in a sequence of objects. Sequences of objects aretypically available as a result of querying a source of data, such as adatabase, using a suitable query such as an SQL query, or UPnP (AKADLNA) Content Directory Service (CDS) [ref:http://www.upnp.org/specs/av/UPnP-av-ContentDirectory-v1-Service.pdf]Search action.

There are frequently cases when a sequence of objects is availablecomprising a plurality of objects, which can be retrieved from thesequence. A query may specify search criteria determining which objectswill be available in the query result and order criteria determiningorder of objects in the query result. For example, in relationaldatabases a table is a container of records, that can be queried withSELECT statements, the search criteria are specified with a WHERE clauseand the order criteria are specified with the ORDER BY clause. Anotherexample is UPnP CDS Search action with accordingly specifiedSearchCriteria and SortCriteria.

A result of such a query is a sequence of objects. The objects may beconsidered to reside at consecutive, unique indexes (or otherwise uniqueidentifiers or keys) in the sequence being a result set of a query. Itis not relevant what is a format of the unique index as long as eachobject in the sequence has a different value of the index.

The query results are typically expressed by an iterator-like API, forexample, SQL database cursor, or StartingIndex and RequestedCount pairin UPnP CDS Search action. Such approach provides a fragment of thequery result sequence at a time, instead of the whole result objectsset. This may improve transmission and storage performance. Theiterator/fragment is related to an index in the sequence, at which anobject (or number of objects) is provided.

In order to access objects from the sequence, that are not available atcurrent iterator/fragment index, the iterator/fragment shall be moved toa new index. The index move operation may be time-consuming orasynchronous, thus iteration over the whole sequence is not a trivialtask.

However, in many applications only a fragment of the query resultsequence is under concern, what makes this approach a convenient andcommonly used pattern.

It is frequently needed to determine an index of an object in a sequencefor example in order to request the next object in the sequence.Typically databases do not include nested records that referenceprevious/next records. This approach would be inefficient because theprevious/next references would have to be rebuilt with each ordering ofthe sequence.

Therefore, there exists a problem of efficient determination of an indexof an object in a sequence of objects wherein the unique identifier ofthe object is known. Preferably, the solution shall determine whetherthe object exists in the sequence.

It would be thus desirable to provide an improved method for determiningan index of an object in a sequence of objects.

The object of the present invention is a method for determining an indexof an object in a sequence of objects, the method comprising the stepsof: obtaining a unique identifier value of a given object O; obtaining aquery definition Q of a sequence, the Q query including an orderdefinition according to a parameter of the O object; constructing a Q′query based on the Q query, the Q′ query being different from the Qquery by having a reversed ordering of results, with respect to the Qquery, and providing results having said parameter value of objectspreceding or matching the parameter value of the object O in thesequence of objects in the Q query result set; executing the Q′ query bya query execution engine; checking whether the object O is present asthe first item in Q′ result set and in case it is, obtaining the indexof the O object in Q sequence by retrieving objects count of the Q′result set.

Preferably, the unique identifier value is a numerical value.

Advantageously, the identifier of the object and the parameter of orderdefinition are the same properties of the object O.

Preferably, prior to constructing query Q′, the values of parameters ofthe object O are obtained.

Preferably, if the query Q ordering is not strict, then query Q isreplaced by query Q1 by the additional order criteria that makes Q1ordering strict.

Preferaby, the additional order criteria, in said Q1 query, refer tounique identifiers of objects.

Advantageously, the executed query Q′ is constructed in such a way, thatthe retrieval of the total count of the Q′ results utilizes the alreadyavailable results.

Preferably, the query is executed in an SQL database.

Preferably, the query is executed in a UPnP CDS.

Another object of the present invention is a computer program comprisingprogram code means for performing all the steps of the method accordingto the present invention when said program is run on a computer.

Another object of the present invention is a computer readable mediumstoring computer-executable instructions performing all the steps of themethod according to the present invention when executed on a computer.

Yet another object of the present invention is a system for determiningan index of an object in a sequence of objects, the system comprising:an object O register configured to store a unique identifier value of agiven object O; a source query Q register configured to store a querydefinition Q of a sequence, the Q query including an order definitionaccording to a parameter of the O object; a destination query registerconfigured to store a newly constructed Q′ query based on the Q query;wherein a source query order inverter is configured to reverse orderingof results, with respect to the Q query; a controller configured toobtain the output of the source query order inverter and define the Q′query, the Q′ query being different from the Q query by, providingresults having parameter's value of objects preceding or matching theparameter value of the object O in the sequence of objects in the Qquery result set; the controller being further configured to: requestexecution of the Q′ query by a query execution engine and check whetherthe object O is present as the first item in Q′ result set and if it is,obtain the index of the O object in Q sequence by retrieving objectscount of Q′ result set.

The present invention is shown by means of exemplary embodiments on adrawing, in which:

FIG. 1 presents a method according to the present invention;

FIG. 2 presents an example of a use of the method according to thepresent invention; and

FIG. 3 presents a system according to the present invention.

NOTATION AND NOMENCLATURE

Some portions of the detailed description which follows are presented interms of data processing procedures, steps or other symbolicrepresentations of operations on data bits that can be performed oncomputer memory. Therefore, a computer executes such logical steps thusrequiring physical manipulations of physical quantities.

Usually these quantities take the form of electrical or magnetic signalscapable of being stored, transferred, combined, compared, and otherwisemanipulated in a computer system. For reasons of common usage, thesesignals are referred to as bits, packets, messages, values, elements,symbols, characters, terms, numbers, or the like.

Additionally, all of these and similar terms are to be associated withthe appropriate physical quantities and are merely convenient labelsapplied to these quantities. Terms such as “processing” or “creating” or“transferring” or “executing” or “determining” or “detecting” or“obtaining” or “selecting” or “calculating” or “generating” or the like,refer to the action and processes of a computer system that manipulatesand transforms data represented as physical (electronic) quantitieswithin the computer's registers and memories into other data similarlyrepresented as physical quantities within the memories or registers orother such information storage.

According to the present invention it is assumed that identity of anobject O is known a′priori. The identity may refer to some uniqueidentifier or a primary key of the object. In database structures(typically tables) a unique key or primary key is a key that uniquelydefines the characteristics of each row. The primary key has to consistof characteristics that cannot collectively be duplicated by any otherrow. In UPnP CDS the identity is defined by means of ObjectID.

Nevertheless, all properties of the object O are not necessarily knowna′priori.

There is also an assumption that a query Q definition (parameters) isknown a′priori. This query may be defined by a user of the system. Asalready indicated, another assumption is that the order of objects inthe query result sequence is deterministic, that is the query Q ordercriteria are defined in the way, that the order is strict.

A query result representing a sequence is a finite sequence and itscardinality is easily available. For example, in case of an SQL Databasetogether with each record data, an additional count column (count(*) inSQL) may be added. For another example, in case of UPnP CDS Searchaction the TotalMatches provides information on the sequencecardinality. Note, that the cardinality information is typicallyprovided as a part of each Search action result.

The problem is to determine if a given object O can be found in theresult sequence of a given query Q. A more specific problem is todetermine an index of the object O in the result sequence of the queryQ, or tell that such index does not exist.

A solution of the present invention is to construct a query Q′, the Q′query being different from the Q query in that: (a) If an object is inresults sequence of Q′. then it is in result sequence of Q, (b) Onlyobjects that compares less than or equal to O are in results of Q′ and(c) Q′ order is the reverted order of Q. Less than or equal meanspreceding or matching O in the sequence of objects in Q result set.

The result of the above is that if the object Q is in the resultssequence of Q′, then it is the first element in this sequence (thus maybe easily obtained, without iteration). Hence, only this single firstelement of Q′ results has to be checked to solve the problem. Further,if the object O is in the results set of the Q query, then its index, inthe Q query results sequence, is equal to total size of results sequenceof the Q′ query (starting from index 1).

If the Q query order is not strict (there can exist objects with randomorder in results sequence), then the above solution cannot be applieddirectly. However, the Q query may be easily changed to some Q1 query inorder to provide a strict ordering by adding appropriate secondary ordercriteria, that is by the objects' identity (that may be any unique key,including the aforementioned primary key).

The queries Q′ for the Q queries may be constructed automatically withan analysis of its search criteria and order criteria: The Q′ ordercriteria are the reverted Q query order criteria, and the Q′ querysearch criteria may be constructed as Q query search criteria AND<condition, that objects precede or equal the object O>. The revertedorder criteria means, that each ascending order parameter Pi in Qbecomes descending order parameter Pi in Q′, and each descending orderparameter Pi in Q becomes ascending order parameter Pi in Q′.

The condition that objects precede or equal the O object with therespect to the Q query order) may be automatically established from theQ query order criteria. In an exemplary embodiment, the followingprocedure may be applied for this purpose.

Let the Q query be ordered by P1 . . . Pn parameters, where P1 is aparameter of the primary ordering criterion, the P2 is a parameter ofthe secondary ordering criterion and so on. Let O.Pi denote the value ofparameter Pi of the object O. The condition that the object precedes orequals 0, with respect to parameters Pi . . . Pn, may be expressed in arecursive way as a Ci condition such that:

-   -   Ci: Pi<O.Pi OR (Pi=O.Pi AND Ci+1)−when i<=n and Pi order is        ascending;    -   Ci: Pi>O.Pi OR (Pi=O.Pi AND Ci+1)−when i<=n and Pi order is        descending; and    -   Ci: TRUE−otherwise (when i=n+1).

Thus the C1 is the desired condition that an object precedes or equals Owith respect to Q ordering criteria.

Example: In SQL the query Q specification may look like: “SELECT*FROMaTable WHERE foo<=10 ORDER BY bar ASC, baz DESC” and the object Oproperties have values {foo: 7, bar: 4, baz: 70}, Then the specificationof Q′ would be: “SELECT*FROM aTable WHERE (foo<=10) AND (bar<4 OR (bar=4AND (baz>70 OR (baz=70 AND TRUE)))) ORDER BY bar DESC, baz ASO”.Equivalent example for UPnP CDS can easily be constructed.

FIG. 1 presents a method according to the present invention. Theprocedure starts at step 101 from obtaining a unique identifier value ofa given object. Typically, such an identifier will be a numerical valuesuch as an integer value. Subsequently, at step 102, there is obtained aquery definition (The Q query as explained previously) of a sequence,the query including an order definition according to a parameter of theO object. For the sake of completeness, it is irrelevant whether step102 is executed after or before or in parallel to step 101.

Next, at step 102 a, values of parameters that are present in the querydefinition from step 102, are obtained for the object O, preferably witha use of the unique identifier, from step 101, of this object O. If thevalues for the object O of the parameters from step 102 are knowna′priori, then the step 102 a may be omitted.

It is to be noted that the identifier of the object O and the parameterof order definition may be the same properties of the object O, such as,for example, they refer to the same column of a database table.

Next, at step 103, there is constructed a Q′ query based on the Q query,the Q′ having reversed ordering of results, with respect to the Q query,and providing results having said parameter's value of objects less thanor equal to the parameter's value of the object 0. Less than or equalmeans preceding or matching the O in the sequence of objects in Q queryresult set. The parameters values obtained in step 102 a may be used tocomplete the Q′ query definition.

For example, if the Q query result set shall have an ascending order onColumn1 values, the Q′ query shall have a descending order on Column1values. Additionally, the Q′ query requires a condition that theidentifier's value is equal or less than (Less than or equal here meanspreceding or matching the O in the sequence of objects in the Q queryresult set) than the value of the object O identifier's value. In casethe Q query has a descending order, the Q′ lists all objects having theselected parameter greater than or equal (Greater than or equal heremeans preceding or matching O in the sequence of objects in the Q queryresult set) than the value of the object O parameter's value (eg.identifier).

Subsequently, at step 104, there is executed (by a query executionengine such as a database server engine) the Q′ query followed by step105 of checking whether the object O is present as the first item in Q′query result set. If it is, the index of the O object in the Q querysequence is obtained at step 106 by counting (or retrieving the countof) items in the Q′ query result set and subsequently assigning theitems count as the index of the object O in the Q query result set.Preferably, the retrieval of the total count of the Q′ results (106)utilizes the already available results.

FIG. 2 presents an example of a use of the method according to thepresent invention. The example concerns a list of television channels201 that may be sorted using different criteria. In this example eachtelevision channel comprises a name. an identifier and a viewingfrequency (the higher the value the frequently the channel is viewed).It is to be understood that many different additional channel parametersmay be present such as a genre, a parental rating, a current contenttype and similar.

While the user operates a television set or a television signal decoderor a tablet or the like, the user may set channels order according to adescending order of viewing frequency parameter, as shown in 202.Subsequently, on the 202 list the user may set channel “Channel 4” asthe currently selected channel for viewing 203.

In such a case the query Q 204 is defined as: SELECT*FROM CHANNELS ORDERBY “Viewing Frequency” DESC. In turn, the Q′ query 205 is defined as:SELECT*FROM CHANNELS WHERE “Viewing Frequency”>=32 ORDER BY “ViewingFrequency” ASC.

The order of the Q query is reversed in the Q′ query and a parameter isadded based on the properties of the current channel 203 namely “ViewingFrequency” being>=32 defining values preceding the O in the original Qquery. The final result of the 205 query is that the object O is presentin the Q′ query result set and the index of the O in the result set ofthe Q query is 2 (1 being the first index value).

In case where the query Q 206 is defined as: SELECT*FROM CHANNELS ORDERBY “Viewing Frequency” ASC, the Q′ query 207 is defined as: SELECT*FROMCHANNELS WHERE “Viewing Frequency”=<32 ORDER BY “Viewing Frequency”DESC. The order of Q is reversed in Q′ and a parameter is added based onthe properties of the current channel 203 namely “Viewing Frequency”being=<32 defining values preceding O in the original Q query. The finalresult of the 207 query is that the object O is present in the Q′ queryresult set and the index of the O object in the result set of the Q is 4(1 being the first index value).

Therefore, a selection between “>” and “<” depends on the sorting orderin the Q result set sequence since the result set of Q′ is to list allobjects preceding the O object in the sequence of Q result set, whilediscarding these following O.

In case the O object is in the Q′ query result set it will be the firstobject and the number of objects in the Q′ result set will determine theindex of the O in the result set of the Q query.

FIG. 3 presents a system according to the present invention. Ifimplemented in hardware, as in an alternative embodiment, the presentsystem can be implemented with any suitable combination of discretelogic circuits having logic gates for implementing logic functions upondata signals, such as an application specific integrated circuit (ASIC)having appropriate logic gates, a programmable gate array(s) (PGA) or afield programmable gate array (FPGA), etc.

The system comprises a data bus 301. that may communicate internal aswell as external modules. For example, an external module may input asource query Q in a source query register 307 and input object O data inan object O register 303.

The controller 304 is configured to communicate the query Q, present inthe source query register 307, to a source query order extractor 306that reports to the controller 304 information defining sorting orderpresent in the Q query. Subsequently, the controller 304 communicateswith a source query order inverter in order to invert the order of thequery stored in the source query register 307.

The controller 304 is configured to communicate with the object Oregister 303 in order to extract the value of the object O of theparameter used in the sorting process, that is the value of 32 of“viewing frequency: as shown in FIG. 2 example. Once the controller isin possession of the input query, the inverted query order and the valueof the parameter of the object O, the controller 304 outputs, to adestination query register a Q′ query taking into account an appropriateuse of “<” or “>” parameters as explained with reference to FIGS. 1 and2.

The controller 304 is further configured to request execution 104 of theQ′ query by a query execution engine and to check 105 whether the objectO is present as the first item in the Q′ query result set and if it is,to obtain the index of the O object in the Q sequence 106 by retrievingobjects count of the Q′ result set.

The controller 304 may further comprise an internal memory for storingcomputer software that provides instructions for the controller. Theinstructions for the controller allow for execution of the methodaccording to the present invention.

It can be easily recognized, by one skilled in the art, that theaforementioned method for determining an index of an object in asequence of objects may be performed and/or controlled by one or morecomputer programs. Such computer programs are typically executed byutilizing the computing resources of the device. The computer programscan be stored in a non-volatile memory, for example a flash memory or ina volatile memory (or otherwise a non-transitory computer readablemedium), for example RAM and are executed by the processing unit. Thesememories are exemplary recording media for storing computer programscomprising computer-executable instructions performing all the steps ofthe computer-implemented method according the technical conceptpresented herein. While the invention presented herein has beendepicted, described, and has been defined with reference to particularpreferred embodiments, such references and examples of implementation inthe foregoing specification do not imply any limitation on theinvention. It will, however, be evident that various modifications andchanges may be made thereto without departing from the broader scope ofthe technical concept. The presented preferred embodiments are exemplaryonly, and are not exhaustive of the scope of the technical conceptpresented herein.

Accordingly, the scope of protection is not limited to the preferredembodiments described in the specification, but is only limited by theclaims that follow.

In addition, any combination of the appended claims in envisaged in thepresent application.

1. A method for determining an index of an object in a sequence ofobjects, the method being characterized in that it comprises the stepsof: obtaining (101) a unique identifier value of a given object O;obtaining (102) a query definition Q of a sequence, the Q queryincluding an order definition according to a parameter of the O object;constructing (103) a Q′ query based on the Q query, the Q′ query beingdifferent from the Q query by having a reversed ordering of results,with respect to the Q query, and providing results having said parametervalue of objects preceding or matching the parameter value of the objectO in the sequence of objects in the Q query result set; executing (104)the Q′ query by a query execution engine; checking (105) whether theobject O is present as the first item in Q′ result set and in case itis, obtaining the index of the O object in Q sequence (106) byretrieving objects count of the Q′ result set.
 2. The method accordingto claim 1 characterized in that the unique identifier value is anumerical value.
 3. The method according to claim 1 characterized inthat the identifier of the object and the parameter of order definitionare the same properties of the object 0,
 4. The method according toclaim 1 characterized in that prior to constructing query Q′ (103), thevalues of parameters of the object O are obtained (102A).
 5. The methodaccording to claim 1 characterized in that if the query ordering is notstrict, then query Q is replaced by query Q1 by the additional ordercriteria that makes Q1 ordering strict.
 6. The method according to claim5 characterized in that the additional order criteria, in said Q1 query,refer to unique identifiers of objects.
 7. The method according to claim1 characterized in that the executed query Q′ (104) is constructed (103)in such a way, that the retrieval of the total count of the Q′ results(106) utilizes the already available results.
 8. The method according toclaim 1 characterized in that the query is executed in an SQL database.9. The method according to claim 1 characterized in that the query isexecuted in a UPnP CDS.
 10. A computer program comprising program codemeans for performing all the steps of the method according to claim 1when said program is run on a computer.
 11. A computer readable mediumstoring computer-executable instructions performing all the steps of themethod according to claim 1 when executed on a computer.
 12. A systemfor determining an index of an object in a sequence of objects, thesystem being characterized in that it comprises: an object O register(303) configured to store (101) a unique identifier value of a givenobject O; a source query Q register (307) configured to store (102) aquery definition Q of a sequence, the Q query including an orderdefinition according to a parameter of the O object; a destination queryregister (302) configured to store a newly constructed (103) Q′ querybased on the Q query; wherein a source query order inverter (305) isconfigured to reverse ordering of results. with respect to the Q query;a controller (304) configured to obtain the output of the source queryorder inverter (305) and define the Q′ query, the Q′ query beingdifferent from the Q query by, providing results having parameter'svalue of objects preceding or matching the parameter value of the objectO in the sequence of objects in the Q query result set; the controller(304) being further configured to: request execution (104) of the Q°query by a query execution engine and check (105) whether the object Ois present as the first item in Q′ result set and if it is, obtain theindex of the O object in Q sequence (106) by retrieving objects count ofQ′ result set.